package com.example.controller.tribune;

import com.example.common.Result;
import com.example.model.entity.tribune.Collect;
import com.example.model.entity.tribune.Like;
import com.example.service.tribune.LikeService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 点赞信息表前端操作接口
 **/
@RestController
@RequestMapping("/like")
@Api(tags = "点赞信息接口")
public class LikeController {

    @Resource
    private LikeService likeService;

    /**
     * 新增
     */
    @ApiOperation(value = "新增点赞信息")
    @PostMapping("/add")
    public Result add(@RequestBody Like like) {
        likeService.add(like);
        return Result.success();
    }

    /**
     * 是否点赞
     */
    @ApiOperation(value = "新增收藏信息")
    @PostMapping("/save")
    public Result save(@RequestBody Like like) {
        likeService.save(like);
        return Result.success();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除点赞信息")
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        likeService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @ApiOperation(value = "批量删除点赞信息")
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        likeService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改点赞信息")
    @PutMapping("/update")
    public Result updateById(@RequestBody Like like) {
        likeService.updateById(like);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @ApiOperation(value = "根据ID查询点赞信息")
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Like like = likeService.selectById(id);
        return Result.success(like);
    }
    /**
     * 根据用户ID和商品ID查询
     */
    @GetMapping("/selectByUserId")
    public Result selectByUserId(Integer userId,Integer fid,String module) {
        Like like = likeService.selectByUserId(userId,fid,module);
        return Result.success(like);
    }

    /**
     * 查询所有
     */
    @ApiOperation(value = "查询所有点赞信息")
    @GetMapping("/selectAll")
    public Result selectAll(Like like) {
        List<Like> list = likeService.selectAll(like);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @ApiOperation(value = "分页查询点赞信息")
    @GetMapping("/selectPage")
    public Result selectPage(Like like,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Like> page = likeService.selectPage(like, pageNum, pageSize);
        return Result.success(page);
    }

}
